package com.cby.assist.kits;

import android.app.Application;
import android.util.SparseArray;

import com.cby.assist.kits.core.OliveManager;
import com.cby.assist.kits.ui.MainKitsActivity;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

/**
 * @description: 辅助工具对外一致接口
 * @author: ChenBaoYang
 * @createDate: 2022/3/7 11:15 上午
 */
public class OliveAssistKits {

    private static SparseArray<List<IKit>> sKitMap = new SparseArray();

    public static void install(Application app, List<IKit> selfKits, Class<?>... classes) {
        if (selfKits != null) {
            List<IKit> biz = sKitMap.get(0);
            if (biz != null) {
                biz.clear();
                biz.addAll(selfKits);

                for (IKit kit : biz) {
                    kit.onAppInit(app);
                }
            }else {
                List<IKit> bizList = new ArrayList<>();
                bizList.addAll(selfKits);
                for (IKit kit : bizList) {
                    kit.onAppInit(app);
                }
                sKitMap.put(0,bizList);
            }
        }
        List<Class<?>> ignoreClz = new ArrayList<>();
        ignoreClz.add(MainKitsActivity.class);
        ignoreClz.addAll(Arrays.asList(classes));
        OliveManager.getInstance().setFloat(app.getApplicationContext(), ignoreClz);
    }

    public static List<IKit> getKitList(int category) {
        return sKitMap.get(category) != null ? new ArrayList(sKitMap.get(category)) : null;
    }
}
